/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ChoosePaymentPanel.java
 *
 * Created on Feb 22, 2011, 12:28:40 PM
 */

package POSTApp;
import Payment.Payment;

/**
 *
 * @author beckie
 */
public class ChoosePaymentPanel extends PaymentPanel {

    /** Creates new form ChoosePaymentPanel */
    public ChoosePaymentPanel() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        choosePopup = new javax.swing.JComboBox();
        chooseLabel = new javax.swing.JLabel();
        choosePanel = new javax.swing.JPanel();

        choosePopup.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Cash", "Check", "Credit" }));
        choosePopup.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                choosePopupItemStateChanged(evt);
            }
        });

        chooseLabel.setText("Pay With:");

        org.jdesktop.layout.GroupLayout choosePanelLayout = new org.jdesktop.layout.GroupLayout(choosePanel);
        choosePanel.setLayout(choosePanelLayout);
        choosePanelLayout.setHorizontalGroup(
            choosePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 238, Short.MAX_VALUE)
        );
        choosePanelLayout.setVerticalGroup(
            choosePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 43, Short.MAX_VALUE)
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(chooseLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(choosePopup, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(choosePanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(chooseLabel)
                    .add(choosePopup, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
            .add(choosePanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void choosePopupItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_choosePopupItemStateChanged
        String choice = choosePopup.getSelectedItem().toString();
        if (choice.equalsIgnoreCase("Cash")) {
            choosePanel.removeAll();
            choosePanel.setLayout(new java.awt.BorderLayout());
            choosePanel.add(new CashPaymentPanel(), java.awt.BorderLayout.CENTER);
            this.revalidate();
        }
        if (choice.equalsIgnoreCase("Check")) {
            choosePanel.removeAll();
            choosePanel.setLayout(new java.awt.BorderLayout());
            choosePanel.add(new CheckPaymentPanel(), java.awt.BorderLayout.CENTER);
            this.revalidate();
        }
        if (choice.equalsIgnoreCase("Credit")) {
            choosePanel.removeAll();
            choosePanel.setLayout(new java.awt.BorderLayout());
            choosePanel.add(new CreditPaymentPanel(), java.awt.BorderLayout.CENTER);
            this.revalidate();
        }
    }//GEN-LAST:event_choosePopupItemStateChanged


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel chooseLabel;
    private javax.swing.JPanel choosePanel;
    private javax.swing.JComboBox choosePopup;
    // End of variables declaration//GEN-END:variables

    public Payment getPayment(float total) {
        if (choosePanel.getComponentCount() != 1)
            return null;
        java.awt.Component c = choosePanel.getComponent(0);
        if (!(c instanceof PaymentPanel))
            return null;
        PaymentPanel pp = (PaymentPanel)c;
        return pp.getPayment(total);
    }

    public void clearPayment() {
        if (choosePanel.getComponentCount() != 1)
            return;
        java.awt.Component c = choosePanel.getComponent(0);
        if (!(c instanceof PaymentPanel))
            return;
        PaymentPanel pp = (PaymentPanel)c;
        pp.clearPayment();
    }
}
